package com.xbongbong.pro.batch.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataDeleteBatchDTO;
import com.xbongbong.paas.pojo.dto.FormDataThoroughDeleteDTO;
import com.xbongbong.paas.pojo.dto.FormDataUpdateBatchDTO;
import com.xbongbong.paas.pojo.vo.FormDataDeleteBatchVO;
import com.xbongbong.paas.pojo.vo.FormDataThoroughDeleteVO;
import com.xbongbong.paas.pojo.vo.FormDataUpdateBatchVO;
import com.xbongbong.paas.pojo.vo.FormDataUpdateVO;
import com.xbongbong.paas.redis.PaasRedisHelper;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.thread.TransmittableThreadLocalUtil;
import com.xbongbong.paas.toolbox.wrap.BaseVO;
import com.xbongbong.paas.toolbox.wrap.CancelRestoreBaseVO;
import com.xbongbong.paas.toolbox.wrap.XbbResponse;
import com.xbongbong.parent.interfaces.BusinessDeleteService;
import com.xbongbong.pro.businessdata.pojo.dto.FocusDTO;
import com.xbongbong.pro.businessdata.pojo.vo.FollowVO;
import com.xbongbong.pro.constant.XbbProConstant;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.listbatch.pojo.dto.AddCoUserDTO;
import com.xbongbong.pro.listbatch.pojo.dto.AddLabelDTO;
import com.xbongbong.pro.listbatch.pojo.dto.AddMainUserDTO;
import com.xbongbong.pro.listbatch.pojo.dto.ArchiveDTO;
import com.xbongbong.pro.listbatch.pojo.dto.CancelDTO;
import com.xbongbong.pro.listbatch.pojo.dto.ChangeMainDTO;
import com.xbongbong.pro.listbatch.pojo.dto.CreditFreezeDTO;
import com.xbongbong.pro.listbatch.pojo.dto.CreditRevokeDTO;
import com.xbongbong.pro.listbatch.pojo.dto.DelCoUserDTO;
import com.xbongbong.pro.listbatch.pojo.dto.DelMainUserDTO;
import com.xbongbong.pro.listbatch.pojo.dto.DelRemindDTO;
import com.xbongbong.pro.listbatch.pojo.dto.DistributionDTO;
import com.xbongbong.pro.listbatch.pojo.dto.IsolationAddCoUserDTO;
import com.xbongbong.pro.listbatch.pojo.dto.IsolationCreateTeamDTO;
import com.xbongbong.pro.listbatch.pojo.dto.IsolationDelCoUserDTO;
import com.xbongbong.pro.listbatch.pojo.dto.IsolationDisbandTeamDTO;
import com.xbongbong.pro.listbatch.pojo.dto.ListBatchDTO;
import com.xbongbong.pro.listbatch.pojo.dto.OnlineDTO;
import com.xbongbong.pro.listbatch.pojo.dto.PortionCompetitorDepDTO;
import com.xbongbong.pro.listbatch.pojo.dto.PortionCompetitorUserDTO;
import com.xbongbong.pro.listbatch.pojo.dto.PortionDepDTO;
import com.xbongbong.pro.listbatch.pojo.dto.PortionMoveCompetitorDepDTO;
import com.xbongbong.pro.listbatch.pojo.dto.PortionMoveCompetitorUserDTO;
import com.xbongbong.pro.listbatch.pojo.dto.PortionMoveDepDTO;
import com.xbongbong.pro.listbatch.pojo.dto.PortionMoveUserDTO;
import com.xbongbong.pro.listbatch.pojo.dto.PortionUserDTO;
import com.xbongbong.pro.listbatch.pojo.dto.ProductionStatusDTO;
import com.xbongbong.pro.listbatch.pojo.dto.RemindDTO;
import com.xbongbong.pro.listbatch.pojo.dto.RemoveLableDTO;
import com.xbongbong.pro.listbatch.pojo.dto.StatusChangeDTO;
import com.xbongbong.pro.listbatch.pojo.dto.UpdatePublicGroupDTO;
import com.xbongbong.pro.listbatch.pojo.dto.UpdateRemindDTO;
import com.xbongbong.pro.listbatch.pojo.vo.RemindVO;
import com.xbongbong.pro.listbatch.pojo.vo.TeamBatchVO;
import com.xbongbong.saas.service.ListBatchService;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;
import java.util.Objects;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/2/20 22:47
 * @since v1.0
 */
@RestController
@RequestMapping(XbbProConstant.API_ROOT_PREFIX + "/batch")
public class ListBatchController {
    @Resource
    private ListBatchService listBatchService;
    @Resource
    private PaasRedisHelper paasRedisHelper;
    @Resource
    private Map<Integer, BusinessDeleteService> businessDeleteMap;

    /**
     * 批量归档
     * @param archiveDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/archive", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String archive(@RequestBody @Valid ArchiveDTO archiveDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(archiveDTO.getSaasMark(), archiveDTO.getBusinessType(), null, DistributorMarkEnum.OTHER.getCode());
                BaseVO baseVO = listBatchService.archive(archiveDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 批量分配
     * @param distributionDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/distribution", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String distribution(@RequestBody @Valid DistributionDTO distributionDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(distributionDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(distributionDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                BaseVO baseVO = listBatchService.distribution(distributionDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 批量退回公海池
     * @param listBatchDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/backCustomer", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String backCustomer(@RequestBody @Valid ListBatchDTO listBatchDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(listBatchDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(listBatchDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                BaseVO baseVO = listBatchService.backCustomer(listBatchDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 批量发票作废
     * @param cancelDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/cancel", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String cancel(@RequestBody @Valid CancelDTO cancelDTO, BindingResult br) {
        XbbResponse<CancelRestoreBaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                CancelRestoreBaseVO cancelRestoreBaseVO = listBatchService.cancel(cancelDTO);
                response = new XbbResponse<>(cancelRestoreBaseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 批量上下架
     * @param onlineDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/online", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String online(@RequestBody @Valid OnlineDTO onlineDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BaseVO baseVO = listBatchService.online(onlineDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * Description:批量添加负责人,现在默认共享模式调用这个接口
     * @param addMainUserDTO
     * @param br
     * @author 刘阳
     * @date 2019/12/23 2:43 PM
     * @since v1.0
     */
    @RequestMapping(value = "/addMainUser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String addMainUser(@RequestBody @Valid AddMainUserDTO addMainUserDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(addMainUserDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(addMainUserDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                TransmittableThreadLocalUtil.setValue(addMainUserDTO.getSaasMark(), addMainUserDTO.getBusinessType(), null, DistributorMarkEnum.OTHER.getCode());
                BaseVO baseVO = listBatchService.addMainUser(addMainUserDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * Description: 批量移除负责人
     * @param delMainUserDTO
     * @param br
     * @return
     * @throws
     * @author 刘阳
     * @date 2019/12/23 2:43 PM
     * @since
     */
    @RequestMapping(value = "/delMainUser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String delMainUser(@RequestBody @Valid DelMainUserDTO delMainUserDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(delMainUserDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(delMainUserDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                TransmittableThreadLocalUtil.setValue(delMainUserDTO.getSaasMark(), delMainUserDTO.getBusinessType(), null, DistributorMarkEnum.OTHER.getCode());
                BaseVO baseVO = listBatchService.delMainUser(delMainUserDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 批量添加协同人
     * @param addCoUserDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/addCoUser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String addCoUser(@RequestBody @Valid AddCoUserDTO addCoUserDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(addCoUserDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(addCoUserDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                TransmittableThreadLocalUtil.setValue(addCoUserDTO.getSaasMark(), addCoUserDTO.getBusinessType(), null, DistributorMarkEnum.OTHER.getCode());
                BaseVO baseVO = listBatchService.addCoUser(addCoUserDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * Description:批量添加负责人，默认隔离模式调用这个接口
     * @param isolationAddCoUserDTO
     */
    @RequestMapping(value = "/addCoUserForIsolation", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String addCoUserForIsolation(@RequestBody @Valid IsolationAddCoUserDTO isolationAddCoUserDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(isolationAddCoUserDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(isolationAddCoUserDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                BaseVO baseVO = listBatchService.addCoUserForIsolation(isolationAddCoUserDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * Description: 批量移除协同人
     * @param delCoUserDTO
     * @param br
     * @author 刘阳
     * @date 2019/12/23 2:42 PM
     * @since v1.0
     */
    @RequestMapping(value = "/delCoUser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String delCoUser(@RequestBody @Valid DelCoUserDTO delCoUserDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(delCoUserDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(delCoUserDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                TransmittableThreadLocalUtil.setValue(delCoUserDTO.getSaasMark(), delCoUserDTO.getBusinessType(), null, DistributorMarkEnum.OTHER.getCode());
                BaseVO baseVO = listBatchService.delCoUser(delCoUserDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 隔离模式下批量删除协同人
     *
     * @param isolationDelCoUserDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/delCoUserForIsolation", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String delCoUserForIsolation(@RequestBody @Valid IsolationDelCoUserDTO isolationDelCoUserDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(isolationDelCoUserDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(isolationDelCoUserDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                BaseVO baseVO = listBatchService.delCoUserForIsolation(isolationDelCoUserDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 批量分配产品给员工
     * @param portionUserDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/portionUser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String portionUser(@RequestBody @Valid PortionUserDTO portionUserDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(portionUserDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(portionUserDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                BaseVO baseVO = listBatchService.portionUser(portionUserDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * Description: 批量移除产品的员工
     * @param portionMoveUserDTO
     * @param br
     * @author 刘阳
     * @date 2020/1/2 5:17 PM
     * @since v1.0
     */
    @RequestMapping(value = "/portionRemoveUser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String portionRemoveUser(@RequestBody @Valid PortionMoveUserDTO portionMoveUserDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(portionMoveUserDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(portionMoveUserDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                BaseVO baseVO = listBatchService.portionRemoveUser(portionMoveUserDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 批量分配竞争对手可见人
     * @param portionUserDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/portionCompetitorUser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String portionCompetitorUser(@RequestBody @Valid PortionCompetitorUserDTO portionUserDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(portionUserDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(portionUserDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                BaseVO baseVO = listBatchService.portionCompetitorUser(portionUserDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 批量移除竞争对手可见人
     * @param portionMoveUserDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/portionRemoveCompetitorUser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String portionRemoveCompetitorUser(@RequestBody @Valid PortionMoveCompetitorUserDTO portionMoveUserDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(portionMoveUserDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(portionMoveUserDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                BaseVO baseVO = listBatchService.portionRemoveCompetitorUser(portionMoveUserDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 批量分配产品给员工
     * @param portionDepDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/portionDep", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String portionDep(@RequestBody @Valid PortionDepDTO portionDepDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BaseVO baseVO = listBatchService.portionDep(portionDepDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * Description: 批量移除产品部门
     * @param portionMoveDepDTO
     * @param br
     * @author 刘阳
     * @date 2020/1/3 6:20 PM
     * @since v1.0
     */
    @RequestMapping(value = "/portionRemoveDep", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String portionRemoveDep(@RequestBody @Valid PortionMoveDepDTO portionMoveDepDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(portionMoveDepDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(portionMoveDepDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                BaseVO baseVO = listBatchService.portionRemoveDep(portionMoveDepDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 批量分配竞争对手可见部门
     * @param portionDepDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/portionCompetitorDep", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String portionCompetitorDep(@RequestBody @Valid PortionCompetitorDepDTO portionDepDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BaseVO baseVO = listBatchService.portionCompetitorDep(portionDepDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * Description: 批量移除竞争对手可见部门
     * @param portionMoveDepDTO
     * @param br
     * @since v1.0
     */
    @RequestMapping(value = "/portionRemoveCompetitorDep", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String portionRemoveCompetitorDep(@RequestBody @Valid PortionMoveCompetitorDepDTO portionMoveDepDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(portionMoveDepDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(portionMoveDepDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                BaseVO baseVO = listBatchService.portionRemoveCompetitorDep(portionMoveDepDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 关注
     * @param focusDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/focus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String focus(@RequestBody @Valid FocusDTO focusDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BaseVO baseVO = listBatchService.focus(focusDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 批量删除数据
     * @param formDataDeleteBatchDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String delete(@RequestBody @Valid FormDataDeleteBatchDTO formDataDeleteBatchDTO, BindingResult br) {
        XbbResponse<FormDataDeleteBatchVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(formDataDeleteBatchDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(formDataDeleteBatchDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                TransmittableThreadLocalUtil.setValue(formDataDeleteBatchDTO.getSaasMark(), formDataDeleteBatchDTO.getBusinessType(), formDataDeleteBatchDTO.getMenuId(), formDataDeleteBatchDTO.getDistributorMark());
                FormDataDeleteBatchVO formDataDeleteBatchVO = listBatchService.deleteBatch(formDataDeleteBatchDTO);
                response = new XbbResponse<>(formDataDeleteBatchVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 删除单独数据
     * @param formDataDeleteBatchDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/deleteSingle", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String deleteSingle(@RequestBody @Valid FormDataDeleteBatchDTO formDataDeleteBatchDTO, BindingResult br) {
        XbbResponse<FormDataDeleteBatchVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(formDataDeleteBatchDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(formDataDeleteBatchDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                TransmittableThreadLocalUtil.setValue(formDataDeleteBatchDTO.getSaasMark(), formDataDeleteBatchDTO.getBusinessType(), formDataDeleteBatchDTO.getMenuId(), formDataDeleteBatchDTO.getDistributorMark());
                TransmittableThreadLocalUtil.setValue(formDataDeleteBatchDTO.getSaasMark(), formDataDeleteBatchDTO.getBusinessType(), formDataDeleteBatchDTO.getMenuId(), formDataDeleteBatchDTO.getDistributorMark());
                FormDataDeleteBatchVO formDataDeleteBatchVO = listBatchService.deleteBySingle(formDataDeleteBatchDTO);
                response = new XbbResponse<>(formDataDeleteBatchVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 批量更新数据
     * @param formDataUpdateBatchDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String update(@RequestBody @Valid FormDataUpdateBatchDTO formDataUpdateBatchDTO, BindingResult br) {
        XbbResponse<FormDataUpdateBatchVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataUpdateBatchDTO.getSaasMark(), formDataUpdateBatchDTO.getBusinessType(), formDataUpdateBatchDTO.getMenuId(), formDataUpdateBatchDTO.getDistributorMark());
                FormDataUpdateBatchVO formDataUpdateBatchVO = listBatchService.updateBatch(formDataUpdateBatchDTO);
                response = new XbbResponse<>(formDataUpdateBatchVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取最近跟进
     * @param listBatchDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/getLastFollow", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getLastFollow(@RequestBody @Valid ListBatchDTO listBatchDTO, BindingResult br) {
        XbbResponse<FollowVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FollowVO followVO = listBatchService.getLastFollow(listBatchDTO);
                response = new XbbResponse<>(followVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 批量设置生产单状态
     * @param productionStatusDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/setProductionStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String setProductionStatus(@RequestBody @Valid ProductionStatusDTO productionStatusDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BaseVO baseVO = listBatchService.setProductionStatus(productionStatusDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 批量发票作废
     * @param listBatchDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/setPaymentStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String setPaymentStatus(@RequestBody @Valid ListBatchDTO listBatchDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(listBatchDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(listBatchDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                BaseVO baseVO = listBatchService.setStatus(listBatchDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 批量客户还原
     * @param listBatchDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/revert", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String revert(@RequestBody @Valid ListBatchDTO listBatchDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BaseVO baseVO = listBatchService.revert(listBatchDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 批量客户捞取
     * @param listBatchDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/customerGrab", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String customerGrab(@RequestBody @Valid ListBatchDTO listBatchDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            // 判断是否跳过重复提交校验
            if (!Boolean.TRUE.equals(listBatchDTO.getIgnoreConCheck())) {
                //重复提交校验
                if (!paasRedisHelper.checkConcurrentLock(listBatchDTO)) {
                    response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                    return JSON.toJSONString(response);
                }
            }
            try {
                BaseVO baseVO = listBatchService.customerGrab(listBatchDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    /**
     * 批量加入访客计划
     *
     * @param formDataAddDTO 入参
     * @param br 结果
     * @return 是否成功
     */
    @RequestMapping(value = "/joinCommunicatePlan", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String joinCommunicatePlan(@RequestBody @Valid FormDataAddDTO formDataAddDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataAddDTO.getSaasMark(), formDataAddDTO.getBusinessType(), formDataAddDTO.getMenuId(), formDataAddDTO.getDistributorMark());
                BaseVO baseVO = listBatchService.joinCommunicatePlan(formDataAddDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 批量加入跟进提醒
     *
     * @param formDataAddDTO 入参
     * @param br 结果
     * @return 是否成功
     */
    @RequestMapping(value = "/pushNotify", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String pushNotify(@RequestBody @Valid FormDataAddDTO formDataAddDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataAddDTO.getSaasMark(), formDataAddDTO.getBusinessType(), formDataAddDTO.getMenuId(), formDataAddDTO.getDistributorMark());
                BaseVO baseVO = listBatchService.pushNotify(formDataAddDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    /**
     * 获取跟进提醒
     *
     * @param remindDTO 入参
     * @param br 结果
     * @return 是否成功
     */
    @RequestMapping(value = "/remind/get", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getRemind(@RequestBody @Valid RemindDTO remindDTO, BindingResult br) {
        XbbResponse<RemindVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                RemindVO remindVO = listBatchService.getRemind(remindDTO);
                response = new XbbResponse<>(remindVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    /**
     * 删除提醒
     * @param delRemindDTO 入参
     * @param br 结果
     * @return 是否成功
     */
    @RequestMapping(value = "/remind/delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String delRemind(@RequestBody @Valid DelRemindDTO delRemindDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(delRemindDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(delRemindDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                BaseVO baseVO = listBatchService.deleteRemind(delRemindDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 编辑提醒
     * @param updateRemindDTO 入参
     * @param br 结果
     * @return 是否成功
     */
    @RequestMapping(value = "/remind/update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String updateRemind(@RequestBody @Valid UpdateRemindDTO updateRemindDTO, BindingResult br) {
        XbbResponse<FormDataUpdateVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                listBatchService.updateRemind(updateRemindDTO);
                FormDataUpdateVO formDataUpdateVO = new FormDataUpdateVO();
                formDataUpdateVO.setCode(1);
                formDataUpdateVO.setMsg("操作成功");
                response = new XbbResponse<>(formDataUpdateVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 信用账户冻结/解冻
     * @author xingxing.xiao
     */
    @RequestMapping(value = "/credit/freeze", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String creditFreeze(@RequestBody @Valid CreditFreezeDTO creditFreezeDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BaseVO baseVO = listBatchService.creditFreeze(creditFreezeDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 临时额度撤销/重新生效
     * @author xingxing.xiao
     */
    @RequestMapping(value = "/credit/revoke", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String creditRevoke(@RequestBody @Valid CreditRevokeDTO creditRevokeDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BaseVO baseVO = listBatchService.creditRevoke(creditRevokeDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 彻底删除
     */
    @RequestMapping(value = "/thorough/delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String thoroughDelete(@RequestBody @Valid FormDataThoroughDeleteDTO formDataThoroughDeleteDTO, BindingResult br) {
        XbbResponse<FormDataThoroughDeleteVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormDataThoroughDeleteVO formDataThoroughDeleteVO = listBatchService.thoroughDelete(formDataThoroughDeleteDTO);
                response = new XbbResponse<>(formDataThoroughDeleteVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 批量添加标签
     * @param addLabelDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/add/label", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String addLabel(@RequestBody @Valid AddLabelDTO addLabelDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(addLabelDTO.getSaasMark(), addLabelDTO.getBusinessType(), addLabelDTO.getMenuId(), addLabelDTO.getDistributorMark());
                BaseVO baseVO = listBatchService.addLabelBatch(addLabelDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    @RequestMapping(value = "/remove/label", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String removeLabel(@RequestBody @Valid RemoveLableDTO removeLableDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(removeLableDTO.getSaasMark(), removeLableDTO.getBusinessType(), removeLableDTO.getMenuId(), removeLableDTO.getDistributorMark());
                BaseVO baseVO = listBatchService.removeLabelbatch(removeLableDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 账号禁用
     */
    @RequestMapping(value = "/status/change", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String changeStatus(@RequestBody @Valid StatusChangeDTO statusChangeDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BaseVO baseVO = listBatchService.changeStatus(statusChangeDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 列表页批量创建团队
     *
     * @param isolationCreateTeamDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/createTeam", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String createTeam(@RequestBody @Valid IsolationCreateTeamDTO isolationCreateTeamDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(isolationCreateTeamDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(isolationCreateTeamDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                BaseVO baseVO = listBatchService.createTeam(isolationCreateTeamDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 解散团队
     *
     * @param isolationDisbandTeamDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/disbandTeam", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String disbandTeam(@RequestBody @Valid IsolationDisbandTeamDTO isolationDisbandTeamDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(isolationDisbandTeamDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(isolationDisbandTeamDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                BaseVO baseVO = listBatchService.disbandTeam(isolationDisbandTeamDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 隔离模式下移交负责人
     * @param changeMainDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/changeMain", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String changeMain(@RequestBody @Valid ChangeMainDTO changeMainDTO, BindingResult br) {
        XbbResponse<TeamBatchVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 判断是否跳过重复提交校验
                if (!Boolean.TRUE.equals(changeMainDTO.getIgnoreConCheck())) {
                    //重复提交校验
                    if (!paasRedisHelper.checkConcurrentLock(changeMainDTO)) {
                        response = new XbbResponse<>(new XbbException(SystemErrorCodeEnum.API_ERROR_100003));
                        return JSON.toJSONString(response);
                    }
                }
                TeamBatchVO teamBatchVO = listBatchService.changeMain(changeMainDTO);
                response = new XbbResponse<>(teamBatchVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 批量变更公海分组
     */
    @RequestMapping(value = "/publicGroup/change", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String changePublicGroupBatch(@RequestBody @Valid UpdatePublicGroupDTO updatePublicGroupDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if(br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(SaasMarkEnum.SAAS.getCode(), updatePublicGroupDTO.getBusinessType(), null, DistributorMarkEnum.OTHER.getCode());
                BaseVO baseVO = listBatchService.changePublicGroupBatch(updatePublicGroupDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
}
